unit uBalanceRecord;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, cxStyles, dxSkinscxPCPainter, cxCustomData, cxFilter,
  cxData, cxDataStorage, cxNavigator, Data.DB, cxDBData, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, cxGroupBox, Datasnap.DBClient, ClientRowSet, cxImageComboBox,
  cxPCdxBarPopupMenu, cxPC, Vcl.ComCtrls, dxCore, cxDateUtils, cxDropDownEdit,
  cxTextEdit, cxMaskEdit, cxCalendar, Vcl.StdCtrls, Vcl.ActnList, Vcl.Menus,
  cxButtons, cxMemo;

type
  TFrmBalanceRecord = class(TForm)
    dsRecord: TDataSource;
    crsRecord: TClientRowSet;
    crsRecordID: TStringField;
    crsRecordORDER_ID: TStringField;
    crsRecordTRADE_NO: TStringField;
    crsRecordCRT_BY: TStringField;
    crsRecordSOURCE_TYPE: TSmallintField;
    crsRecordPAY_STATE: TSmallintField;
    crsRecordPAY_TIME: TStringField;
    crsRecordPAY_AMOUNT: TFloatField;
    crsRecordEMP_NO: TStringField;
    crsRecordEMP_NAME: TStringField;
    crsRecordCRT_DT: TStringField;
    crsRecordCHANNEL_ID: TStringField;
    crsRecordUPD_DT: TStringField;
    crsRecordVERSION: TIntegerField;
    crsRecordDISABLED: TSmallintField;
    crsRecordSTATUS: TSmallintField;
    crsRecordEVAL_ID: TStringField;
    crsRecordOUT_TRADE_NO: TStringField;
    crsRecordBILL_NO: TStringField;
    crsRecordCON_NO: TLargeintField;
    crsRecordCON_NAME: TStringField;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    GrdBasic: TcxGrid;
    tvBasic: TcxGridDBTableView;
    tvBasicBILL_NO: TcxGridDBColumn;
    tvBasicPAY_TIME: TcxGridDBColumn;
    tvBasicPAY_AMOUNT: TcxGridDBColumn;
    tvBasicCON_NO: TcxGridDBColumn;
    tvBasicCON_NAME: TcxGridDBColumn;
    tvBasicPAY_STATE: TcxGridDBColumn;
    tvBasicSOURCE_TYPE: TcxGridDBColumn;
    tvBasicEMP_NO: TcxGridDBColumn;
    tvBasicEMP_NAME: TcxGridDBColumn;
    lvEXP_COMP: TcxGridLevel;
    cxGroupBox1: TcxGroupBox;
    Label2: TLabel;
    Label4: TLabel;
    edtDateFrom: TcxDateEdit;
    edtDateTo: TcxDateEdit;
    cbPayState: TcxImageComboBox;
    cbSource: TcxImageComboBox;
    Label1: TLabel;
    Label3: TLabel;
    ActionList1: TActionList;
    actQuery: TAction;
    cxButton1: TcxButton;
    dsEval: TDataSource;
    crsEval: TClientRowSet;
    crsEvalID: TStringField;
    crsEvalORDER_ID: TStringField;
    crsEvalEMP_NO: TStringField;
    crsEvalEMP_NAME: TStringField;
    crsEvalEVAL_SCORE: TFloatField;
    crsEvalEVAL_CONTENT: TStringField;
    crsEvalCRT_DT: TStringField;
    crsEvalCHANNEL_ID: TStringField;
    crsEvalUPD_DT: TStringField;
    crsEvalVERSION: TIntegerField;
    crsEvalDISABLED: TSmallintField;
    crsEvalSTATUS: TSmallintField;
    crsEvalEVAL_TAG: TStringField;
    crsEvalCUST_ID: TStringField;
    crsEvalANONYMOUS_TAG: TSmallintField;
    crsEvalDEST_TYPE: TSmallintField;
    crsEvalCUST_NAME: TStringField;
    crsEvalBILL_NO: TStringField;
    DataSource1: TDataSource;
    GrdEval: TcxGrid;
    tvEval: TcxGridDBTableView;
    lvEval: TcxGridLevel;
    tvEvalCRT_DT: TcxGridDBColumn;
    tvEvalBILL_NO: TcxGridDBColumn;
    tvEvalANONYMOUS_TAG: TcxGridDBColumn;
    tvEvalEVAL_SCORE: TcxGridDBColumn;
    tvEvalEVAL_TAG: TcxGridDBColumn;
    tvEvalEVAL_CONTENT: TcxGridDBColumn;
    tvEvalDEST_TYPE: TcxGridDBColumn;
    cxGroupBox2: TcxGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    edtBegin: TcxDateEdit;
    edtEnd: TcxDateEdit;
    cxButton2: TcxButton;
    actFind: TAction;
    procedure actQueryExecute(Sender: TObject);
    procedure actFindExecute(Sender: TObject);
    procedure tvBasicCustomDrawIndicatorCell(Sender: TcxGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
      var ADone: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    empno:string;
    { Public declarations }
  end;

var
  FrmBalanceRecord: TFrmBalanceRecord;
  procedure FrmBalanceRecordShow(sEmpNo:string);

implementation

{$R *.dfm}

uses uDm, ucommFunction, Console;

procedure FrmBalanceRecordShow(sEmpNo:string);
begin
  Application.CreateForm(TFrmBalanceRecord,FrmBalanceRecord);
  with FrmBalanceRecord do
  begin
    edtDateFrom.Date:=Date-30;
    edtDateTo.Date:=Date;
    edtBegin.Date:=Date-30;
    edtEnd.Date:=Date;
    empno:=sEmpNo;
    actQuery.Execute;
    actFind.Execute;
    ShowModal;
  end;
end;

procedure TFrmBalanceRecord.actFindExecute(Sender: TObject);
var
  sqls:string;
begin
  sqls:='select t.*,b.bill_no from TSP_ORDER_EVAL t left join tsp_order b on t.order_id=b.order_id '+
        ' where t.emp_no='+QuotedStr(empno)+' and t.CRT_DT>='+QuotedStr(edtBegin.Text)+' and t.CRT_DT<='+QuotedStr(edtEnd.Text+' 23:59:59');
  OpenDataSet(sqls,crsEval);
end;

procedure TFrmBalanceRecord.actQueryExecute(Sender: TObject);
var
  sqls:string;
begin
  sqls:='select a.*,b.bill_no,c.con_no,c.con_name from TSP_ORDER_REWARD a left join'+
        ' tsp_order b on a.order_id=b.order_id left join bas_member c on a.crt_by=c.id ' +
        ' where a.emp_no='+QuotedStr(empno)+' and a.pay_time>='+QuotedStr(edtDateFrom.Text)+' and a.pay_time<='+QuotedStr(edtDateTo.Text+' 23:59:59');
  if Trim(cbPayState.Text)<>'' then
    sqls:=sqls+' and pay_state='+VarToStr(cbPayState.EditValue);
  if Trim(cbSource.Text)<>'' then
    sqls:=sqls+' and SOURCE_TYPE='+VarToStr(cbSource.EditValue);
  OpenDataSet(sqls,crsRecord);
end;

procedure TFrmBalanceRecord.FormCreate(Sender: TObject);
begin
  pSetCaption(Self);
end;

procedure TFrmBalanceRecord.tvBasicCustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    FValue :=IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
    FBounds := AViewInfo.Bounds;
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    InflateRect(FBounds, -1, -1);
    //ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

end.
